count = 0
gold = 5000
print('猜数字')
print('你共有金币%d' % gold)
while gold > 0:
    import random
    ran = random.randint(1, 50)
    while True:
        guess = int(input('请输入数字：'))
        count = count + 1
        if guess == ran:
            gold = gold + 3000
            print('猜对了，奖励3000金币，你还剩金币%d' % gold)
            break
        elif guess > ran:
            gold = gold - 500
            print('大了，扣除500金币，你还剩金币%d' % gold)
        else:
            gold = gold - 500
            print('小了, 扣除500金币，你还剩金币%d' % gold)
print('你一共猜了%d'% count)
